package com.peng.leetcode.other;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * LevelTree
 *
 * @author: lupeng6
 * @create: 2021/4/7 11:48
 */
public class LevelTree {

    public static void main(String[] args) {
        String a = "abc";
        String b = "abc";
        String c = new String("abc");
        System.out.println(a == b);
        System.out.println(a == c);
    }


    public List<Integer> levelOrder(TreeNode node) {
        if (node == null) {
            return null;
        }
        List<Integer> answer = new ArrayList<>();

        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(node);

        while (!queue.isEmpty()) {
            TreeNode n = queue.poll();

            answer.add(n.val);

            TreeNode l = n.left;
            TreeNode r = n.right;
            if (l != null) {
                queue.offer(l);
            }
            if (r != null) {
                queue.offer(r);
            }
        }

        return answer;
    }


    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
    }
}
